package songgao.papers.iEC;

import javax.jdo.annotations.Extension;
import javax.jdo.annotations.IdGeneratorStrategy;
import javax.jdo.annotations.IdentityType;
import javax.jdo.annotations.PersistenceCapable;
import javax.jdo.annotations.Persistent;
import javax.jdo.annotations.PrimaryKey;

@PersistenceCapable(identityType = IdentityType.APPLICATION, detachable = "true")
public class Parameters {
	
	public static Parameters generateDefault(){
		Parameters r = new Parameters();
		r.setGeneLowerBound(0);
		r.setGeneSize(8);
		r.setGeneUpperBound(8);
		r.setMaxGeneration(1000);
		r.setMigrationInterval(50);
		r.setMigrationStrategyName("SimpleAnnularMigrationStrategy");
		r.setPopulationPoolSize(16);
		r.setPopulationSize(100);
		r.setSlavePerformanceTracingDepth(4);
		r.setTaskTimeLimit(15000);
		r.setTaskTimeoutMultiple(2);
		return r;
	}

	@PrimaryKey
	@Persistent(valueStrategy = IdGeneratorStrategy.IDENTITY)
	@Extension(vendorName = "datanucleus", key = "gae.encoded-pk", value = "true")
	private String encodedKey;

	@Persistent
	private int slavePerformanceTracingDepth;

	@Persistent
	private int migrationInterval;

	@Persistent
	private int populationSize;

	@Persistent
	private int populationPoolSize;

	@Persistent
	private int geneSize;

	@Persistent
	private int geneLowerBound;

	@Persistent
	private int geneUpperBound;

	@Persistent
	private String migrationStrategyName;

	@Persistent
	private long taskTimeLimit;

	@Persistent
	private float taskTimeoutMultiple;

	@Persistent
	private int maxGeneration;

	/**
	 * @param slavePerformanceTracingDepth
	 *            the slavePerformanceTracingDepth to set
	 */
	public void setSlavePerformanceTracingDepth(int slavePerformanceTracingDepth) {
		this.slavePerformanceTracingDepth = slavePerformanceTracingDepth;
	}

	/**
	 * @return the slavePerformanceTracingDepth
	 */
	public int getSlavePerformanceTracingDepth() {
		return slavePerformanceTracingDepth;
	}

	/**
	 * @param encodedKey
	 *            the encodedKey to set
	 */
	public void setEncodedKey(String encodedKey) {
		this.encodedKey = encodedKey;
	}

	/**
	 * @return the encodedKey
	 */
	public String getEncodedKey() {
		return encodedKey;
	}

	/**
	 * @param migrationInterval
	 *            the migrationInterval to set
	 */
	public void setMigrationInterval(int migrationInterval) {
		this.migrationInterval = migrationInterval;
	}

	/**
	 * @return the migrationInterval
	 */
	public int getMigrationInterval() {
		return migrationInterval;
	}

	/**
	 * @param populationSize
	 *            the populationSize to set
	 */
	public void setPopulationSize(int populationSize) {
		this.populationSize = populationSize;
	}

	/**
	 * @return the populationSize
	 */
	public int getPopulationSize() {
		return populationSize;
	}

	/**
	 * @param populationPoolSize
	 *            the populationPoolSize to set
	 */
	public void setPopulationPoolSize(int populationPoolSize) {
		this.populationPoolSize = populationPoolSize;
	}

	/**
	 * @return the populationPoolSize
	 */
	public int getPopulationPoolSize() {
		return populationPoolSize;
	}

	/**
	 * @param geneSize
	 *            the geneSize to set
	 */
	public void setGeneSize(int geneSize) {
		this.geneSize = geneSize;
	}

	/**
	 * @return the geneSize
	 */
	public int getGeneSize() {
		return geneSize;
	}

	/**
	 * @param geneLowerBound
	 *            the geneLowerBound to set
	 */
	public void setGeneLowerBound(int geneLowerBound) {
		this.geneLowerBound = geneLowerBound;
	}

	/**
	 * @return the geneLowerBound
	 */
	public int getGeneLowerBound() {
		return geneLowerBound;
	}

	/**
	 * @param geneUpperBound
	 *            the geneUpperBound to set
	 */
	public void setGeneUpperBound(int geneUpperBound) {
		this.geneUpperBound = geneUpperBound;
	}

	/**
	 * @return the geneUpperBound
	 */
	public int getGeneUpperBound() {
		return geneUpperBound;
	}

	/**
	 * @param migrationStrategyName
	 *            the migrationStrategyName to set
	 */
	public void setMigrationStrategyName(String migrationStrategyName) {
		this.migrationStrategyName = migrationStrategyName;
	}

	/**
	 * @return the migrationStrategyName
	 */
	public String getMigrationStrategyName() {
		return migrationStrategyName;
	}

	/**
	 * @param taskTimeLimit
	 *            the taskTimeLimit to set
	 */
	public void setTaskTimeLimit(long taskTimeLimit) {
		this.taskTimeLimit = taskTimeLimit;
	}

	/**
	 * @return the taskTimeLimit
	 */
	public long getTaskTimeLimit() {
		return taskTimeLimit;
	}

	/**
	 * @param taskTimeoutMultiple
	 *            the taskTimeoutMultiple to set
	 */
	public void setTaskTimeoutMultiple(float taskTimeoutMultiple) {
		if (taskTimeoutMultiple > 1)
			this.taskTimeoutMultiple = taskTimeoutMultiple;
	}

	/**
	 * @return the taskTimeoutMultiple
	 */
	public float getTaskTimeoutMultiple() {
		return taskTimeoutMultiple;
	}

	public long getTaskTimeoutLimit() {
		return Math.round(this.taskTimeoutMultiple * this.taskTimeLimit);
	}

	/**
	 * @param maxGeneration
	 *            the maxGeneration to set
	 */
	public void setMaxGeneration(int maxGeneration) {
		this.maxGeneration = maxGeneration;
	}

	/**
	 * @return the maxGeneration
	 */
	public int getMaxGeneration() {
		return maxGeneration;
	}

}
